/**
 *  Copyright (c) 2017-2022 Rushang Co.Ltd All Rights Reserved.
 */
package com.rshang.rsdp.util.excel;

import java.io.OutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;
import org.springframework.web.servlet.view.document.AbstractXlsView;

/**
 * 功能简介：<br/>
 * @author zhangjun
 * @create 2017年8月23日下午9:07:32
 * 
 */
public class ExcelView extends AbstractXlsView {

	private String fileName;
	private Workbook workbook;
	
	
	public ExcelView(String fileName,Workbook workbook) {
		super();
		this.fileName = fileName;
		this.workbook = workbook;
	}

	@Override
	protected void buildExcelDocument(Map<String, Object> map, Workbook wb, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setContentType(this.getContentType());     
        response.setHeader("Content-disposition", "attachment;filename=" + this.fileName);     
        OutputStream ouputStream = response.getOutputStream();     
        workbook.write(ouputStream);     
        ouputStream.flush();     
        ouputStream.close(); 
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}


}
